package com.nuumoblie.bluetoothtools.utils;

import android.util.Log;

import java.io.File;
import java.text.DecimalFormat;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class Utils {
    private static final String TAG = Utils.class.getSimpleName();
    public static final Executor EXECUTOR = Executors.newCachedThreadPool();

    public static void mkdirs(String filePath) {
        boolean mk = new File(filePath).mkdirs();
        Log.d(TAG, "mkdirs: " + mk);
    }

    /**
     * 将字节 byte 转为对应的合适的单位
     *
     * @return
     */
    public static String getFileSizeDescription(long size) {
        //定义GB/MB/KB的计算常量
        double GB = 1024.0 * 1024.0 * 1024.0;
        double MB = 1024.0 * 1024.0;
        double KB = 1024.0;
        StringBuffer bytes = new StringBuffer();
        DecimalFormat df = new DecimalFormat("###.00");
        if (size >= GB) {
            double i = (size / GB);
            bytes.append(df.format(i)).append("GB");
        }
        else if (size >= MB) {
            double i = (size / MB);
            bytes.append(df.format(i)).append("MB");
        }
        else if (size >= KB) {
            double i = (size / KB);
            bytes.append(df.format(i)).append("KB");
        }
        else {
            if (size <= 0) {
                bytes.append("0B");
            }
            else {
                bytes.append((int) size).append("B");
            }
        }
        return bytes.toString();
    }

}
